package com.watson.jpa.result;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description: TODO
 * @Author watson
 * @Date 2022/8/10 10:47
 * @Version 1.0
 */
//@ControllerAdvice({"com.github.wxiaoqi", "com.ams.archive", "com.ams.users", "com.ams.activiti","com.ams.workflow"})
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
    @ExceptionHandler(Exception.class)
    @Order(3)
    public ObjectRestResponse otherExceptionHandler(HttpServletResponse response, Exception ex) {
        response.setStatus(200);
        logger.error(ex.getMessage(), ex);
        ObjectRestResponse result = new ObjectRestResponse().msg("系统异常，请联系管理人员");
        result.setCode(500);
        return result;
    }
}
